package com.ruoyi.common.enums.base;

/**
 * @ClassName TransactionType
 * @Description TODO
 * @Author Mr、Liu
 * @Date 2025/7/3 18:33
 * @Version 1.0
 */
/**
 * 交易类型枚举
 */
public enum TransactionType {

    /** 入账 */
    INCOME(1, "入账"),

    /** 出账 */
    OUTCOME(2, "出账");

    private final int code;
    private final String desc;

    TransactionType(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据 code 获取交易类型枚举
     */
    public static TransactionType of(int code) {
        for (TransactionType type : values()) {
            if (type.code == code) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的交易类型 code: " + code);
    }
}
